﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections.Specialized;
namespace EETOP.OAuthSDK
{
   public class Util
    {
       internal static Uri GetRequestUrlFromContext()
       {
           HttpContext current = HttpContext.Current;
           if (current == null)
           {
               throw new InvalidOperationException("Current HttpContext Required");
           }
           return new Uri(current.Request.Url, current.Request.RawUrl);
       }
       public static string AddParams(string url, NameValueCollection paras)
       {
           ;
           string result = url;
           if (!new Uri(url).Query.StartsWith("?"))
           {
               result += "?";
           }
           if (paras != null)
           {
               for (int i = 0; i < paras.Count; i++)
               {
                   result += string.Format("{0}={1}&", paras.GetKey(i), HttpContext.Current.Server.UrlEncode(paras.Get(i)));
               }
           }
           url.Remove(url.Length - 1);
           return result;
       }
 

    }
}
